﻿
/*

命名空间:Lib

类    名:DHTML

        方法:


        属性:


*/




Lib.Windows = {};

var Win = Lib.Windows;

//打开一个新窗体，窗体居中
/*
参数：
    sURL 网页地址
    w 窗口的宽度
    h 窗口的高度
    [可选] setting 设置的参数，枚举值
    {
        scrollbars:"yes"|"no",
        menubar:"yes"|"no",
        status:"yes"|"no",
        toolbar:"yes"|"no",
        resizable:"yes"|"no",
        location:"yes"|"no"  
    }

用法:

    var set = {scrollbars:"no",menubar:"yes"}
    Lib.Windows.Open('www.163.com',400,500,set);


*/
Win.Open = function(sURL, w, h) {
    var sw = parseInt(screen.availWidth);
    var sh = parseInt(screen.availHeight);

    if (w > sw) w = sw;
    if (h > sh) h = sh;

    var left = (sw - w) / 2;
    var top = (sh - h) / 2;


    var scrollbars = "yes";
    var menubar = "yes";
    var status = "yes";
    var toolbar = "yes";
    var resizable = "yes";
    var location = "yes";

    //取系统参数
    if (arguments.length == 4) {
        var arg = arguments[3];

        scrollbars = arg.scrollbars != null ? arg.scrollbars : "no";
        menubar = arg.menubar != null ? arg.menubar : "no";
        status = arg.status != null ? arg.status : "no";
        toolbar = arg.toolbar != null ? arg.toolbar : "no";
        resizable = arg.resizable != null ? arg.resizable : "no";
        location = arg.location != null ? arg.location : "no";
    }

    var sFeatures = "height={0},width={1},left={2},top={3},status={6},toolbar={7},resizable={8},scrollbars={4},menubar={5},location={9}";
    sFeatures = sFeatures.Format(h, w, left, top, scrollbars, menubar, status, toolbar, resizable, location)


    //alert(sFeatures);
    var name = Math.random() + "fff";
    name = name.substr(name.indexOf(".") + 1);

    // alert(name);
    window.open(sURL, name, sFeatures);

    //window.open(sURL);
}

/*
参数：sTitle 新窗口标题
      sURL 网页地址
      vArguments 参数  见showModalDialog 的参数


*/
Win.ShowModalDialog = function(sTitle,sURL ,vArguments)
{
    sURL = encodeURIComponent(sURL);   //编码地址作为参数传递
    sURL = "/Script/win.htm?url=" + sURL + "&rnd="+Math.random();
    sURL += "&title=" + sTitle;

    var result = window.showModalDialog(sURL, "", vArguments);
    return result;
}

/*
获取URL地址上的参数值

参数：
    url 地址
    parm 参数名称
*/
Win.GetUrlParameterValue = function(url,parm)
{	
	url = url + "";
	var p = url.substring(url.indexOf('?') + 1);
	var p = p.split('&');
	
	for(var i = 0;i < p.length;i++)
	{
		var pv = p[i].split('=');
		
		if(pv[0].toLowerCase().Trim() == parm.toLowerCase())
		{
			return pv[1].Trim();
		}	
	}

	return "";
}